package com.jinlong.service;

import com.alibaba.fastjson.JSONObject;
import com.jinlong.adapter.MassageAdapter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class SMSMaileboxService implements MassageAdapter{

    @Autowired
    private JavaMailSender javaMailSender;
    @Override
    public void distribute(JSONObject jsonObject) {
        String email = jsonObject.getString("mail");
        String userName = jsonObject.getString("username");

        log.info("###消费者收到消息...email{},userName{}",email,userName);

        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(email);
        simpleMailMessage.setTo(email);
        simpleMailMessage.setSubject("这是站内信发出的信息");
        simpleMailMessage.setText(".......恭喜"+userName+"你的快递已经到家门口了....");
        log.info("###发送消息...email{}",email);
        javaMailSender.send(simpleMailMessage);
    }
}
